<template>
  <g-details :detailData="inputData" :inputConfig="inputConfig" :rules="rules" @pop="setdata" ref="detail"> </g-details>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
export default {
  name: "dispatchDetails",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  data() {
    return {
      rules: {
        storerKey: [
          { required: true, message: this.$selectPlease('model.deliveryDept'), trigger: "blur" },
        ],
        sku: [
          { required: true, message: this.$selectPlease('model.deliveryDept'), trigger: "blur" },
        ],
        totalQty: [
          { required: true, message: this.$inputPlease('model.deliveryDept'), trigger: "blur" },
        ],
        packUnit: [
          { required: true, message: this.$selectPlease('model.packUnit'), trigger: "biur" },
        ],
      },
    };
  },
  computed: {
    inputConfig() {
      return [
        {
          type: "table",
          label: this.$t("config.shipper"),
          props: "storerKey",
          tableConfig: [
            {
              label: this.$t("config.shipper"),
              prop: "storerkey",
              input: "input",
            },
            {
              label: this.$t("config.company"),
              prop: "company",
              input: "input",
            },
            {
              label: this.$t("config.city"),
              prop: "city",
              input: "input",
            },
            { label: this.$t("config.provice"), prop: "state", input: "input" },
            {
              label: this.$t("config.postcode"),
              prop: "zip",
              input: "input",
            },
          ],
          url: `queryStorer/1/?/${this.$store.state.wms}`,
          filterKey: "storerkey"
        },
        {
          type: "table",
          label: this.$t("config.sku"),
          disabled: !this.inputData.storerkey,
          props: "sku",
          filterKey:["descr","sku"],
          tableConfig: [
            {
              label: this.$t("config.sku"),
              prop: "sku",
              input: "input",
            },
            { label: this.$t("common.desc"), prop: "descr", input: "input" },
            {
              label: this.$t("config.shipper"),
              prop: "storerkey",
              input: "input",
            },
            {
              label: this.$t("config.packaging"),
              prop: "packkey",
              input: "input",
            },
            {
              label: this.$t("config.boxGroup"),
              prop: "cartongroup",
              input: "select",
              options: this.getOptions("queryCartonizationDropDown"),
            },
            {
              label: this.$t("config.allocaStrategy"),
              prop: "strategykey",
              input: "select",
              options: this.getOptions("queryAllocatestrategyDropDown"),
            },
            {
              label: this.$t("config.putawayStrategy"),
              prop: "putawaystrategykey",
              input: "select",
              disabled: false,
              options: this.getOptions("queryPutawaystrategyDropDown"),
            },
            {
              label: this.$t("config.batchValidate"),
              prop: "lottablevalidationkey",
              input: "select",
              options: this.getOptions("queryLottablevalidationDropDown"),
            },
            {
              label: this.$t("config.area"),
              prop: "putawayzone",
              input: "select",
              options: this.getOptions("queryPutawayzoneDropDown"),
            },
          ],
          filterUrl: `fuzzyQuerySkuByItemNumberAndName/undefined`,
          url: `querySkuOfStorerkey/?/${this.$store.state.wms}/undefined`,
        },
        {
          type: "input",
          label: this.$t("config.goodsDesc"),
          disabled: true,
          props: "descr",
        },
        {
          type: "select",
          label: this.$t("model.loadingStatus"),
          props: "loadingStatus",
          options: this.getOptions("codelkup/LoadingStatus"),
          disabled:true,
          break: true,
        },
        {
          type: "input",
          label: this.$t('in.totalpoqty'),
          disabled: false,
          props: "totalQty",
        },
        {
          type: "select",
          label: this.$t("in.packUnit"),
          props: "packUnit",
          options: this.getOptions("codelkup/defaultUom/STD"),
        },
        {
          type: "input",
          label: this.$t('model.loadingQty'),
          props: "loadingQty",
          disabled: true,
          break: true,
        },
        {
          type: "input",
          label: this.$t('model.workNo'),
          props: "workNo",
        },
      ];
    },
  },
  methods: {
    setdata(data, close, prop) {
      if (prop == "storerKey") {
        this.inputData.storerKey = data.storerkey;
        const index = this.inputConfig.findIndex(item => item.props == 'sku');
        this.inputConfig[index].url = this.inputConfig[index].url.replace(
          'undefined',
          this.inputData.storerKey
        )
        this.inputConfig[index].filterUrl = this.inputConfig[
          index
        ].filterUrl.replace('undefined', this.inputData.storerKey)
      } else if (prop == "sku") {
        this.inputData.sku = data.sku;
        this.inputData.descr = data.descr;
      }
      close(false);
    },
    validate(){
      return this.$refs.detail.$refs.from.validate()
    }
  },
  mounted() {
    
  }
};
</script>

<style scoped>

</style>
